package com.handu.luna.boss.controller.support;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

@Aspect
@Component
public class BindingResultErrorAspector {
	protected Log logger = LogFactory.getLog(this.getClass());
	
    @Around("execution(* com.handu.luna.boss.controller.*.*(..))")  
    public Object processTx(ProceedingJoinPoint joinPoint) throws java.lang.Throwable {  
    	Object[] args = joinPoint.getArgs();
    	for(Object arg : args){
    		if(arg instanceof BindingResult){
    			BindingResult result = (BindingResult)arg;
    			for(FieldError error : result.getFieldErrors()){
    				if(error.getDefaultMessage().startsWith("Failed to convert property")){
    					result.rejectValue(error.getField(), "", "输入的格式有误");
    				}
    			}
    		}
    	}
        return joinPoint.proceed(joinPoint.getArgs());  
    }  
}
